<template>
    <addEditBaseWageTypeView ref="addEditBaseWageTypeView" />
    <addFileView ref="addFileView" />
    <el-main>
        <div class="teacher">
            <div class="app-table">
                <div class="app-body">
                    <el-form :inline="true" class="demo-form-inline" v-model="form">
                        <el-form-item label="项目名称">
                            <el-input placeholder="请输入项目名称" v-model="form.wageName"></el-input>
                        </el-form-item>
                        <el-form-item label="工资类型" :label-width="formLabelWidth" prop="wageType">
                            <el-select v-model="form.wageType" placeholder="请选择工资类型" clearable style="width: 192px;">
                                <el-option :value="1" label="通用工资"></el-option>
                                <el-option :value="2" label="国拨"></el-option>
                                <el-option :value="3" label="校内"></el-option>
                                <el-option :value="4" label="奖金"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="工资结构" :label-width="formLabelWidth" prop="wageStructure">
                            <el-select v-model="form.wageStructure" placeholder="请选择工资结构" clearable style="width: 192px;">
                                <el-option :value="1" label="应发工资"></el-option>
                                <el-option :value="2" label="应扣工资"></el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="是否统计" :label-width="formLabelWidth" prop="isStatistics">
                            <el-select v-model="form.isStatistics" placeholder="请选择是否统计" clearable style="width: 192px;">
                                <el-option :value="1" label="统计"></el-option>
                                <el-option :value="2" label="不统计"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button class="serach_btn" @click="onSubmit" plain @keyup.enter="searchEnter">搜索
                            </el-button>
                            <el-button class="add_btn" @click="add" plain>添加</el-button>
                            <!-- <el-button type="warning" @click="exportExcel" plain>导出报表</el-button> -->
                            <!-- <el-button type="danger" @click="importExcel" plain>批量导入<el-icon class="el-icon--right"> -->
                            <!-- <Upload /> -->
                            <!-- </el-icon> -->
                            <!-- </el-button> -->
                        </el-form-item>
                    </el-form>
                    <el-table size="default" :data="list" style="width: 100%" :row-class-name="tableRowClassName">
                        <el-table-column prop="id" label="id" />
                        <el-table-column prop="wageName" label="项目名称" />
                        <el-table-column prop="wageType" label="工资类型">
                            <template #default="scope">
                                {{ scope.row.wageType == 1 ? '通用工资' : scope.row.wageType == 2 ? '国拨' : scope.row.wageType ==
                                    3 ? '校内' : scope.row.wageType == 4 ? '奖金' : '未知' }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="wageStructure" label="工资结构">
                            <template #default="scope">
                                {{ scope.row.wageStructure == 1 ? '应发工资' : scope.row.wageStructure == 2 ? '应扣工资' : '未知' }}
                            </template>
                        </el-table-column>
                        <!-- <el-table-column prop="valueType" label="数值类型"/> -->
                        <el-table-column prop="isStatistics" label="是否统计">
                            <template #default="scope">
                                {{ scope.row.isStatistics == 1 ? '统计' : scope.row.isStatistics == 2 ? '不统计' : '未知' }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="sortId" label="权重" />
                        <!-- <el-table-column prop="enabled" label="0启用、1禁用"/> -->
                        <!-- <el-table-column prop="isDelete" label="是否删除"/> -->
                        <!-- <el-table-column prop="campus" label="校区"/> -->
                        <el-table-column label="操作" width="140px">
                            <template #default="scope">
                                <el-button class="edit_btn" size="small" type="success"
                                    @click="editBaseWageType(scope.row)">编辑</el-button>
                                <el-button class="del_btn" size="small" type="danger"
                                    @click="deleteBaseWageType(scope.row.id)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                        <template v-slot:empty>
                            <el-empty description="暂无数据"></el-empty>
                        </template>
                    </el-table>
                    <el-config-provider :locale="locale">
                        <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                            layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                            @current-change="changeCurrentPage">
                        </el-pagination>
                    </el-config-provider>
                </div>
                <bottomView></bottomView>
            </div>
        </div>
    </el-main>
</template>
<script>
import addEditBaseWageTypeView from "@/components/baseInfo/addEditBaseWageType.vue";
import addFileView from "@/components/addExcelFile.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture, Upload } from "@element-plus/icons-vue";
import bottomView from "@/components/bottom.vue";

export default {
    name: "BaseWageTypeListView",
    data() {
        return {
            type: 0,
            title: "",
            page: 0,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            form: {
                wageName: "",
                isStatistics: "",
                wageType: "",
                wageStructure: ""
            },
        };
    },
    components: {
        addEditBaseWageTypeView,
        addFileView,
        IconPicture, bottomView,
        ElConfigProvider,
        ElMessageBox,
        ElMessage, Upload
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getBaseWageTypeList();
    },
    watch: {
        $route() {
            this.getBaseWageTypeList();
        },
    },
    methods: {
        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getBaseWageTypeList();
            }
        },
        add() {
            this.$refs.addEditBaseWageTypeView.title = "添加工资类型表"
            this.$refs.addEditBaseWageTypeView.personnelType = this.type
            this.$refs.addEditBaseWageTypeView.dialogFormVisible = true;
        },
        editBaseWageType(obj) {
            this.$refs.addEditBaseWageTypeView.title = "修改信息"
            this.$refs.addEditBaseWageTypeView.getBaseWageTypeById(obj.id);
            this.$refs.addEditBaseWageTypeView.dialogFormVisible = true;
        },
        deleteBaseWageType(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/javaApi/baseWageType/deleteById", "id=" + id, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getBaseWageTypeList();
                            } else {
                                ElMessage.error(data.message);
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        reloadData() {
            this.page = 1;
            this.getBaseWageTypeList()
        },
        importExcel() {
            this.$refs.addFileView.dialogFormVisible = true;
            this.$refs.addFileView.title = "批量导入工资类型表";
            this.$refs.addFileView.uploadApiUrl = "/javaApi/baseWageType/importExcel";
        },
        exportExcel() {
            httpService(
                "/javaApi/baseWageType/exportExcel",
                {
                    "wageName": this.form.wageName,
                    isStatistics: this.form.isStatistics,
                    wageType: this.form.wageType,
                    wageStructure: this.form.wageStructure
                },
                "get"
            ).then((data) => {
                if (data.code == 200) {
                    window.open(data.msg, '_blank')
                }
            });
        },
        onSubmit() {
            this.getBaseWageTypeList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getBaseWageTypeList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getBaseWageTypeList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getBaseWageTypeList() {
            httpService(
                "/javaApi/baseWageType/list/" + this.page + "/" + this.pageSize,
                {
                    "wageName": this.form.wageName,
                    isStatistics: this.form.isStatistics,
                    wageType: this.form.wageType,
                    wageStructure: this.form.wageStructure
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
    },
};
</script>
<style scoped>
.el-main {
    padding: 0px;
}

.teacher-content {
    width: 100%;
}

.app-table {
    background: #eff3f5;
    padding:5px 10px 10px;
}

.app-search {
    margin-top: 20px;
}

.app-separator {
    padding-top: 10px;
    padding-bottom: 20px;
    padding-left: 10px;
}

.app-body {
    background: white;
    padding: 20px 20px 10px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 204px);
    text-align: left;

}

.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
    text-align: center;
    margin-top: 10px;
}

.edit_btn {
    background-color: #fff;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}
.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}
.serach_btn {
    background-color: #007EFF;
    color: #fff;
    border-radius: 8px;
    border: none;
}
</style>

